<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>添加入库</title>
    <script type="text/javascript" src="/js/jquery-1.11.1.js"></script>
    <script type="text/javascript" src="/js/bootstrap.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="/css/style.css"/>
    <style>
        label span{color: #ff0000; padding-right: 5px;}
    </style>
</head>

<body>
<h2>添加入库</h2>
<form id="myForm" class="form-horizontal" method="post" action="/team">
    <div class="form-group">
        <label class="col-sm-1 control-label"><span>*</span>入库单号</label>
        <div class="col-sm-9">
            <input required="required" name="in_id" class="form-control" placeholder="请输入 入库单号"/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-1 control-label"><span>*</span>商品编号</label>
        <div class="col-sm-9">
            <input required="" name="p_id" class="form-control" placeholder="请输入 商品编号"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">入库数</label>
        <div class="col-sm-9">
            <input name="in_number" class="form-control" placeholder="请输入 入库数"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">备注</label>
        <div class="col-sm-9">
            <input name="in_remarks" class="form-control" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">仓库</label>
        <div class="col-sm-2">
            <select name="w_id" class="form-control">
                <!--<option value="-1">请选择仓库</option>-->
                <!--<option value="0" name="">环东路</option>-->
                <!--<option value="1" name="">门市</option>-->
            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-1 control-label"></label>
        <div class="col-sm-9">
            <button id="btnAdd" type="button" class="btn btn-sm btn-info">提&nbsp;交</button>
            &nbsp;&nbsp;&nbsp;
            <button type="reset"  class="btn btn-sm btn-warning">重&nbsp;置</button>
        </div>
    </div>
</form>
</body>
</html>
<script>
    $(function () {
        queryByW_name();
        //提交按钮的单击事件
        $("#btnAdd").click(function () {
            $.ajax({
                type: "POST",
                url: "/inpstock/",
                data: $("#myForm").serialize(),
                dataType:"json",
                success: function(vo){
                    if(vo.code==200) {
                        alert("操作成功！");
                        window.location.href = "/pages/Inventory/list.html?pageNum=1&pageSize=5";
                    }else{
                        alert("添加失败！"+vo.msg);
                    }
                }
            });
        });

    });

    function queryByW_name() {
        $.ajax({
            type: "GET",
            url: "/warehouse/",
            data: null,
            dataType: "json",
            success: function(vo){
                let list = vo.list;
                let str = "<option value=\"-1\">请选择仓库</option>";
                for(let i=0 ; i < list.length ; i++){
                    let obj = list[i];
                    let w_name = obj.w_name;
                    let w_id = obj.w_id;
                    str += '<option value="'+w_id+'" name="'+w_name+'">'+w_name+'</option>';
                }
                $("select[name='w_id']").html(str);
            }
        });
    }
</script>